package com.InterestingExercises;

import java.util.Random;

public class 使用String来开发验证码2 {
    public static void main(String[] args) {
        System.out.println("产生的随机验证码是:[" + generateVerificationCode(10) + "]");
    }

    public static String generateVerificationCode(int length) {
        String code = "";
        String template = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$";
        Random rd = new Random();
        for (int i = 0; i < length; i++) {
            code += template.charAt(rd.nextInt(template.length()));//0-63
        }
        return code;
    }
}
